package com.example.venue_reservation_service.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class PasswordGenerator {

    private static final char[] ALPHANUMERIC_CHARS =
            "0123456789abcdefghijklmnopqrstuvwxyz".toCharArray();

    public static String generatePassword() {
        Random random = new Random();
        char[] password = new char[6];

        for (int i = 0; i < 6; i++) {
            int randomIndex = random.nextInt(ALPHANUMERIC_CHARS.length);
            password[i] = ALPHANUMERIC_CHARS[randomIndex];
        }

        return new String(password);
    }

    public static String generateAccount() {
        // 1. 获取当前日期（yymmdd格式）
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd");
        String datePart = dateFormat.format(new Date());

        // 2. 获取时间戳毫秒值，并取最后6位
        long timestamp = System.currentTimeMillis();
        String timestampStr = String.valueOf(timestamp);

        // 确保获取最后6位数字
        String timePart = timestampStr.substring(
                Math.max(0, timestampStr.length() - 6));

        // 3. 组合成账号
        return datePart + timePart;
    }
}